package service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.MonthCallNumberDao;
import dao.impl.MonthCallNumberDaoImpl;
import domain.MonthCallNumber;
import domain.User;

import java.util.List;

public class MonthCallNumberService {
    String valueAsString = null;

    private MonthCallNumberDao monthCallNumberDao = new MonthCallNumberDaoImpl();
    //用户每月通话次数统计
    public String ToJson3(User user) {
        String telephone = user.getTelephone();
        int year = user.getYear();
        List<MonthCallNumber> monthCallNumbers = monthCallNumberDao.SelectMonthCallNumberByTelephone(telephone, year);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            valueAsString = objectMapper.writeValueAsString(monthCallNumbers);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return valueAsString;
    }
}
